<?php

ini_set("display_errors", "true");
error_reporting(E_ALL);

$inst_conf_file = dirname(dirname(__FILE__))."/etc/inst-config.json";
if (!file_exists($inst_conf_file)) {
	die("Check availability of file: ".$inst_conf_file);
}
$G["inst_def"] = json_decode(file_get_contents($inst_conf_file));
if (!isset($G["inst_def"]->inst_type)) {
	die("Failed to determine inst_type");
}
$G["top_dir"] = $G["inst_def"]->top_dir;
$G["inst_type"] = $G["inst_def"]->inst_type;

// ******************************************************************
// Directories
// ******************************

define("TOP_DIR", $G["inst_def"]->top_dir);

set_include_path(get_include_path().PATH_SEPARATOR.TOP_DIR."/lib/include");
set_include_path(get_include_path().PATH_SEPARATOR.TOP_DIR."/lib/classes");
set_include_path(get_include_path().PATH_SEPARATOR.TOP_DIR."/lib/languages");

define("ETC_DIR_BASE", TOP_DIR."/etc");
define("LOGS_DIR", TOP_DIR."/logs");
define("LOCK_DIR", TOP_DIR."/.locks");
define("TEMPORARY_DIR_BASE", TOP_DIR."/tmp");
define("LANGS_DIR", TOP_DIR."/lib/languages");
define("TEMPLATES_DIR", TOP_DIR."/lib/templates");

define("DEFAULT_LANG", "ru");

// ******************************************************************
// Files
// ******************************

// ******************************************************************
// HTTP URLs
// ******************************

// Set up memcache
if (class_exists('Memcache')) {
	$G_Memcache = new Memcache;
	$G['memcache_opts'] = array();
	$mcservers = explode(',', '127.0.0.1');
	foreach ($mcservers as $mcserver) {
		$G['memcache_opts']['servers'][] = $mcserver;
	}
	$G['memcache_opts']['port'] = '11211';
	$G['memcache'] = $G_Memcache;
} else {
	die("Class 'Memcache' doens't exists");
}

//=============================================================================================

function __autoload($className) {
	$path = TOP_DIR.'/lib/classes/class.'.$className.'.php';

	if (file_exists($path)) {
		require $path;
	}
}

//=============================================================================================

date_default_timezone_set("Europe/Kiev");

$G["sql-errors_email"] = "email@domain.com";
$G["hostname"] = trim(`hostname`).".".trim(`domainname`);
$G["stages"] = array();

?>
